package br.com.android.projetodebar;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class ListViewImagesMain extends Activity {
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_listview);
        
        ArrayList<SearchResults> searchResults = GetSearchResults();
        
        final ListView lv1 = (ListView) findViewById(R.id.ListView01);
        lv1.setAdapter(new MyCustomBaseAdapter(this, searchResults));
        
        lv1.setOnItemClickListener(new OnItemClickListener() {
        	@Override
        	public void onItemClick(AdapterView<?> a, View v, int position, long id) { 
        		Object o = lv1.getItemAtPosition(position);
            	SearchResults fullObject = (SearchResults)o;
        		Toast.makeText(ListViewImagesMain.this, "Bar selecionado foi: " + " " + fullObject.getName(), Toast.LENGTH_LONG).show();
        	}  
        });
    }
    
    private ArrayList<SearchResults> GetSearchResults(){
    	ArrayList<SearchResults> results = new ArrayList<SearchResults>();
    	
    	SearchResults sr1 = new SearchResults();
    	sr1.setName("Bar da Linguiça");
    	sr1.setCityState("Travessa Quartoze de Julho, 53");
    	sr1.setPhone("81-3719-1234");
    	sr1.setImageNumber(1); 
    	results.add(sr1);
    	
    	sr1 = new SearchResults();
    	sr1.setName("Circo 93 Bar");
    	sr1.setCityState("Rua Severino Macêdo, 93");
    	sr1.setPhone("81-9278-2765");
        sr1.setImageNumber(2); 
    	results.add(sr1);
    	
    	sr1 = new SearchResults();
    	sr1.setName("Boteco do Batata");
    	sr1.setCityState("Av. Lion Club, 79");
    	sr1.setPhone("81-9967-9544");
    	sr1.setImageNumber(3); 
    	results.add(sr1);
    	
    	   	
    	return results;
    }
}